﻿using System;
using System.Collections.Generic;
using System.Text;
using DomenModel;
using System.Web.Security;
using System.Configuration;
using Infrastructure.Repositories;
using Model.Repositories;
using Model.Service;
using Model.Repositories.Interfaces;
using System.Linq.Expressions;

namespace Infrastructure.Service
{
    public class OrderingService : IOrderingService
    {
        private IOrderDetailsCrud _dbOrderDetails;
        private IOrderCrud _dbOrder;
        private IItemCrud _dbItem;
        private ICrudItemDimension _dbItemDimesion;


        public OrderingService(IOrderDetailsCrud _dbOrderDetails, IOrderCrud _dbOrder, IItemCrud _dbItem, ICrudItemDimension _dbItemDimesion)
        {
            this._dbOrderDetails = _dbOrderDetails;
            this._dbOrder = _dbOrder;
            this._dbItem = _dbItem;
            this._dbItemDimesion = _dbItemDimesion;
        }

        public OrderingService()
        {
            _dbOrderDetails = new OrderDetailsRepo();
            _dbOrder = new OrderRepo();
            _dbItem = new ItemRepo();
            _dbItemDimesion = new ItemDimensionRepo();
        }




        public List<OrderDetails> GetPaginationListOfOrderDetails(int page, int itemsOnPage, string orderUsersBy, int orderId)
        {
            var list = _dbOrderDetails.GetListForPagination(page,itemsOnPage,false,orderId);
            return list;
        }

        public long GetCountOfOrdersDetails(int orderId)
        {

            return _dbOrderDetails.GetCount(orderId);
        }

        public long GetCountOfOrdersDetails(string searchString, string listSelectField, string listSelectCondition, int orderId)
        {

            return 100;
        }

        public List<Order> GetPaginationListOfOrder(int page, int itemsOnPage, string orderUsersBy,string userName)
        {
            bool descending = false;
            var list = _dbOrder.GetListForPagination(page, itemsOnPage, descending,userName);
            return list;

        }

        public long GetCountOfOrders(string userName)
        {
            return _dbOrder.GetCountOfOrders(userName);
         
        }

        public long GetCountOfOrders(string searchString, string listSelectField, string listSelectCondition, string userName)
        {

            return 100;
        }

        public List<Item> GetItems(string sortOrder,string searchString)
        {
            if (searchString != null)
            {
                var list = _dbItem.GetListForItemPagination(sortOrder, searchString);
                return list;
            }
            else
            {
                var list = _dbItem.GetListForItemPagination(sortOrder);
                return list;
            }
        }

        public void AddItemToOrder(int orderId, int itemId, string name, decimal price, int quantity, string dimension)
        {
            ItemDimension itemDimension = new ItemDimension();
            itemDimension.ItemId = itemId;
            itemDimension.Price = price;
            itemDimension.Quantity = quantity;
            itemDimension.Dimension = 1;

            OrderDetails orderDetails = new OrderDetails();
            orderDetails.ItemDimension = itemDimension;
            orderDetails.OrderId = orderId;


            _dbOrderDetails.Save(orderDetails);

        }

    }
}
